<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>运输费统计表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
	<style type="text/css">
		#dyTable td{border:1px solid #00000080;} 
	</style>
</head>
<body class="layui-anim layui-anim-up">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>运输费统计表</cite>
        </a>
      </span>
    </div>
    <div class="x-body">
      <div style="margin-bottom: 18px">
		<div class="layui-inline layui-form">
			<table>
				<tr>
					<%-- <td>
						<div class="layui-input-block" style="width:180px;margin-left: 10px;">
							<select class="layui-input" id="keyword01" lay-verify="required" lay-search>
								<option value="">请选择科目</option>
								<c:forEach items="${saleExpenseAccounts}" var="saleExpenseAccount">
									<option value="${saleExpenseAccount.eid}">${saleExpenseAccount.ename}</option>
								</c:forEach>  
							</select>
							<input type="hidden" id="ssid" value="${customer_id}">
						</div>
					</td> --%>
					<td>
						<div class="layui-input-block" style="width:180px;margin-left: 10px;">
							<select class="layui-input" id="keyword02" lay-verify="required" lay-search>
								<option value="">请选择供应商</option>
								<c:forEach items="${customers}" var="customer">
									<option value="${customer.id}">${customer.customer_name}</option>
								</c:forEach>  
							</select>
						</div>
					</td>
					<td class="layui-input-inline">
						<input class="layui-input" id="startTime" placeholder="请输入开始时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
						-<input class="layui-input" id="endTime" placeholder="请输入结束时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px"> 
					</td>
				</tr>
			</table>
		</div>
		<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon">&#xe615;</i>检索</button>
	  </div>
	  <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
	  <table class="layui-hide" id="tableListDetails" lay-filter="tableList"></table>
	</div>

	<script type="text/javascript">
        var table;
		layui.use(['table','layer','upload','form','laydate'], function(){
			table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;
			
			//日期时间范围
	    	var minListDate = "1000-01-01 00:00:00";//最小可选时间，例：1990-02-01
	        var maxListDate = "3000-12-31 23:59:59";//最大可选时间，例：2200-12-31   
	        var enddate = laydate.render({
	            elem: "#endTime",
	            format: 'yyyy-MM-dd HH:mm:ss',
	            type: 'datetime',
	            min: minListDate,
	            max: maxListDate,
	            done: function (val, date) {
	                if (date && date.year){
	                	//设置结束时间 设置开始时间的最大值为结束时间
	                    begindate.config.max = {
	                        year: date.year,
	                        month: date.month - 1,//必须减1才是正确值
	                        date: date.date,
	                        hours: date.hours,
	                        minutes: date.minutes,
	                        seconds: date.seconds
	                    };
	                }else {
	                	//清除结束值    设置开始时间最大值
	                    var dateInit = new Date(maxListDate.replace(/-/g, "/"));
	                    begindate.config.max = {
	                        year: dateInit.getFullYear(),
	                        month: dateInit.getMonth(),
	                        date: dateInit.getDate(),
	                        hours: dateInit.getHours(),
	                        minutes: dateInit.getMinutes(),
	                        seconds: dateInit.getSeconds()
	                    };
	                }
	            }
	        });
	        var begindate = laydate.render({
	            elem: "#startTime",
	            format: 'yyyy-MM-dd HH:mm:ss',
	            type: 'datetime',
	            min: minListDate,
	            max: maxListDate,
	            done: function (val, date) {
	                if (date && date.year){
	                	//设置开始时间 设置结束时间的最小值为开始时间
	                    enddate.config.min = {
	                        year: date.year,
	                        month: date.month - 1,
	                        date: date.date,
	                        hours: date.hours,
	                        minutes: date.minutes,
	                        seconds: date.seconds
	                    };
	                }else {
	                	//清除开始值 ，设置结束值最小值
	                    var dateInit = new Date(minListDate.replace(/-/g, "/"));
	                    enddate.config.min = {
	                        year: dateInit.getFullYear(),
	                        month: dateInit.getMonth(),
	                        date: dateInit.getDate(),
	                        hours: dateInit.getHours(),
	                        minutes: dateInit.getMinutes(),
	                        seconds: dateInit.getSeconds()
	                    };
	                }
	            }
	        });
			
			var $ = layui.jquery, active = {
				reload:function () {
					var keyword01 = $.trim($("#keyword01").val());
	                
	                var whereSql = " and dn.status >= 2 ";
	                var keyword02 = $.trim($("#keyword02").val());
					if(keyword02 != null && keyword02 != ""){
						whereSql = whereSql + " and cu.id = '"+keyword02+"' ";
					}
	                var startTime = $.trim($("#startTime").val());
					if(startTime != null && startTime != ""){
						whereSql = whereSql + " and so.arrival_date >= '"+startTime+"' ";
					}
					var endTime = $.trim($("#endTime").val());
					if(endTime != null && endTime != ""){
						whereSql = whereSql + " and so.arrival_date <= '"+endTime+"' ";
					}
	                
					table.reload('tableList',{
						method:'get'
						,where:{
							ename:"运输费"
	                        ,whereSql:whereSql
						}
						,page: {
		                    curr: 1//重新从第 1 页开始
		                }
					});
				}
			}
			$('.layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			var url = '${pageContext.request.contextPath }/saleCustomerExpenseAccount/listReport.do'
			var ssid = $.trim($("#ssid").val());
			if(ssid != null && ssid != ""){
				$("#keyword02").val(ssid)
				$('#keyword02').attr("disabled",true)
				form.render()
			}
			var keyword01 = $.trim($("#keyword01").val());
            var keyword02 = $.trim($("#keyword02").val());
			table.render({
				elem: '#tableList'
				,url:url
				,where:{
					ename:"运输费"
                    ,whereSql:" and dn.status >= 2"
				}
				,toolbar: '#toolbar'
				,title: 'machineList'
				,limits:[10,20,30]
                ,defaultToolbar:['filter', 'print']
				,request: {   //如果无需自定义请求参数，可不加该参数
	                pageName: 'page' //页码的参数名称，默认：page
	                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	            }
	            ,response: {   //如果无需自定义数据响应名称，可不加该参数
	                countName: 'total' //规定数据总数的字段名称，默认：count
	                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
	            }
				,cols: [
		                [{
		                    type: 'checkbox',
		                    fixed: 'left'
		                }, { 
		                	field:'id',
		                	title:'序号', 
		                	sort: true,
		                	width: 60,
		                	type:'numbers',
		                	align:'center'
		                }, {
		                    field: 'id',
		                    title: 'id',
		                    hide:true //是否初始隐藏列，默认：false。layui 2.4.0 新增
		                } , {
		                    field: 'mid',
		                    title: '供应商',
		                    align:'center',
		                    templet: function(d){
		                    	var value = "";
            	    			if(d.customer != null){
            	    				value = d.customer.customer_name
            	    			}
            	    			return value;
            	    		},
		                /* }, {
		                    field: 'kid',
		                    title: '科目',
		                    align:'center',
		                    templet: function(d){
		                    	var value = "";
            	    			if(d.saleExpenseAccount != null){
            	    				value = d.saleExpenseAccount.ename
            	    			}
            	    			return value;
            	    		}, */
		                }, {
		                    field: 'num',
		                    title: '运输趟数',
		                    align:'center',
		                }, {
		                    field: 'unitPrice',
		                    title: '运输单价(元)',
		                    align:'center',
		                }, {
		                    field: 'isTrue',
		                    title: '运输金额',
		                    align:'center',
		                    templet: function(d){
		                    	var value = 0;
            	    			if(d.num != null){
            	    				value = parseFloat(d.unitPrice) * parseFloat(d.num) 
            	    			}
            	    			return value;
            	    		},  
		                }
		                ]
		               ]
				,page: true
				,done : function(){
	                $('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                    //'font-size': 10,
	                })
	            }
			});
			
			table.render({
				elem: '#tableListDetails'
				,url:'${pageContext.request.contextPath }/saleCustomerExpenseAccount/listReportDetails.do'
				,where:{
					ename:"运输费"
                    ,whereSql:"and 1 !=1  and dn.status >= 2"
				}
				,toolbar: '#toolbar'
				,title: 'machineList'
				,limits:[10,20,30]
                ,defaultToolbar:['filter', 'print']
				,request: {   //如果无需自定义请求参数，可不加该参数
	                pageName: 'page' //页码的参数名称，默认：page
	                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	            }
	            ,response: {   //如果无需自定义数据响应名称，可不加该参数
	                countName: 'total' //规定数据总数的字段名称，默认：count
	                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
	            }
				,cols: [
		                [{
		                /*     type: 'checkbox',
		                    fixed: 'left'
		                }, { */
		                	field:'id',
		                	title:'序号', 
		                	sort: true,
		                	width: 60,
		                	type:'numbers',
		                	align:'center'
		                }, {
		                    field: 'id',
		                    title: 'id',
		                    hide:true //是否初始隐藏列，默认：false。layui 2.4.0 新增
		                } , {
		                    field: 'mid',
		                    title: '供应商',
		                    align:'center',
		                    templet: function(d){
		                    	var value = "";
            	    			if(d.customer != null){
            	    				value = d.customer.customer_name
            	    			}
            	    			return value;
            	    		},
		                }, {
		                    field: 'arrival_date',
		                    title: '运输时间',
		                    align:'center',
		                }, {
		                    field: 'number',
		                    title: '配送单号',
		                    align:'center',
		                }
		                ]
		               ]
				,page: true
				,done : function(){
	                $('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                    //'font-size': 10,
	                })
	            }
			});
			//点击行checkbox选中
    	    $(document).on("click",".layui-table-body table.layui-table tbody tr", function () {
    	        var index = $(this).attr('data-index');
    	        var tableBox = $(this).parents('.layui-table-box');
    	        //存在固定列
    	        if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length>0) {
    	            tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
    	        } else {
    	            tableDiv = tableBox.find(".layui-table-body.layui-table-main");
    	        }
    	        var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
    	        if (checkCell.length>0) {
    	            checkCell.click();
    	        }
    	    });
    	    $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
    	        e.stopPropagation();
    	    });
    	    table.on('checkbox(tableList)', function(obj){
	        	if(obj.checked == true && obj.type == 'all'){
	                //点击全选
	                $('.layui-table-body table.layui-table tbody tr').addClass('layui-table-click');
	            }else if(obj.checked == false && obj.type == 'all'){
	                //点击全不选
	                $('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click');
	            }else if(obj.checked == true && obj.type == 'one'){
	                //点击单行
	                if(obj.checked == true){
	                    obj.tr.addClass('layui-table-click');
	                }else{
	                    obj.tr.removeClass('layui-table-click');
	                }
	            }else if(obj.checked == false && obj.type == 'one'){
	                //点击全选之后点击单行
	                if(obj.tr.hasClass('layui-table-click')){
	                    obj.tr.removeClass('layui-table-click');
	                }
	            }
	        });
	        table.on('row(tableList)', function(obj){
	        	var data = obj.data;
	        	var whereSql = " and dn.status >= 2 ";
				whereSql = whereSql + " and cu.id = '"+data.customer.id+"' ";
                var startTime = $.trim($("#startTime").val());
				if(startTime != null && startTime != ""){
					whereSql = whereSql + " and so.arrival_date >= '"+startTime+"' ";
				}
				var endTime = $.trim($("#endTime").val());
				if(endTime != null && endTime != ""){
					whereSql = whereSql + " and so.arrival_date <= '"+endTime+"' ";
				} 
                
				table.reload('tableListDetails',{
					method:'get'
					,where:{
						ename:"运输费"
                        ,whereSql:whereSql
					}
					,page: {
	                    curr: 1//重新从第 1 页开始
	                }
				});
	        });
	        
			
		});
		
		//获取当前时间
	   	function curentTimeNumber() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	 	var hours = now.getHours(); //获取当前小时数(0-23)
		   	var minutes = now.getMinutes(); //获取当前分钟数(0-59)
		   	var seconds = now.getSeconds(); //获取当前秒数(0-59)
	   	    //var mill=now.getMilliseconds();
	   	    var time=year+""+add0(month)+""+add0(day)+""+add0(hours)+""+add0(minutes)+""+add0(seconds);
	   		return time;
	   	}
	    //获取当前时间
	   	function curentTime() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	    var time=year+"-"+add0(month)+"-"+add0(day);
	   		return time;
	   	}
	   	function add0(m){return m<10?'0'+m:m }
		toastrStyle()
	</script>
</body>
</html>